var InterfaceVersionHistoryParam = null;
$(document).ready(function(){
	
		//所属领域下拉框
		$('#comboxSearchfieldName').combobox({
			url: BASE_URL_FIELD_SEARCH + '/findAllOfCurrentUserCanManage' + '?v=' + Math.random(),
			valueField: 'id',
		    textField: 'name',
		    editable: false,
		    method:'get',
		    loadFilter: function(data){
		    	var allCheck = {'id':'','name':'全部'};
		    	data.content.unshift(allCheck);
		    	return data.content;
		    },
		    onSelect: function(record){
		    	comboxSearchSystemName.combobox({
                  disabled: false,
                  method:'get',
                  queryParams: {fieldId: record.id},
                  url: BASE_URL_FIELD_SYSTEM_SEARCH +'/findByFieldOfCurrentUserCanManage' + '?v=' + Math.random(),
                  valueField: 'id',
                  textField: 'name',
				  data:'',
      		    loadFilter: function(data){
      		    	var allCheck = {'id':'','name':'全部'};
      		    	data.content.unshift(allCheck);
      		    	return data.content;
      		    },
      		    onLoadSuccess:function(){
      		    	comboxSearchSystemName.combobox('setValue','');
      		    }
              }).load();
		    },
		    onLoadSuccess:function(){
		    	$('#cbSearch').combobox('setValue','');
		    }
		});
		
		//所属系统下拉框
		var comboxSearchSystemName = $('#comboxSearchSystemName').combobox({
          disabled: true,
          valueField: 'id',
          textField: 'name',
          editable: false,
		  data:[{id:'',name:'全部','selected':'true'}]
      });
	  
	  	
		$('#comboxSearchOperation').combobox({
			url:BASE_URL_DATA_DICTIONARY_VALUE_SEARCH +'/findByTypeCode?typeCode='+DDTC_OPERATION + '&v=' + Math.random(),
			valueField: 'valueCode',
		    textField: 'valueName',
		    editable: false,
		    method:'get',
		    loadFilter: function(data){
		    	var allCheck = {'valueCode':'','valueName':'全部'};
		    	data.unshift(allCheck);
		    	return data;
		    }
		});
		
		$('#comboxSearchSourceChange').combobox({
			valueField: 'id',
			textField: 'name',
			editable: false,
			data:[{id:'',name:'全部',selected:'true'},{id:'1',name:'kettle作业提交'},{id:'0',name:'cook平台维护'}]
		});
		$("#datagrid").datagrid({
			url : BASE_URL_INTERFACE_VERSION_HISTORY_SEARCH + '/findByExample' + '?v=' + Math.random(),
			method:'get',
			autoRowHeight:true,
			nowrap:false,
			singleSelect:true,
			striped:true,
			pageSize:20,
			pageList:[10,20,50,100],
			columns:[[
						{field:'fieldName',title:'领域',width:70},
						{field:'fieldSystemName',title:'系统',width:70},
						{field:'interfaceName',title:'接口名称',width:100,align:'left'},
						{field:'operationForDisplay',title:'操作类型',width:50},
						{field:'changeFromKettle',title:'变更来源',width:100,formatter: 
							function(value,row,index){
									return value ? "kettle作业提交" : "cook平台维护";		
							} 
						},
						{field:'operator',title:'操作人',width:80},
						{field:'operatorTime',title:'操作时间',width:100},
						{field:'version',title:'版本号',width:80}
			      ]],
			pagination:true,
			onSelect:function(rowIndex,rowData){
				$("#toolbar_edit").linkbutton('enable');
				$("#toolbar_delete").linkbutton('enable');
				$(this).datagrid('unselectRow', rowIndex);
			},
			loadFilter:function(data){
				//alert("inData:"+JSON.stringify(data));
				return {
					total: data.totalElements,
					rows: data.content
				};
			},
			onBeforeLoad:function(param){
				param.page -= 1;
				param.size = param.rows;
				delete param.rows;
				
				param.sort = 'createTime,desc';
				
				var fieldName = $('#comboxSearchfieldName').combobox('getText');
				if(fieldName != '全部'){
					//alert("getText:"+fieldName);
					if(fieldName !=""){
						param.fieldName = fieldName;
					}
				}
				
				var fieldSystemName = $('#comboxSearchSystemName').combobox('getText');
				if(fieldSystemName != '全部'){
					//alert("getText:"+fieldSystemName);
					if(fieldSystemName !=""){
						param.fieldSystemName = fieldSystemName;
					}
				}
				
				var operation = $('#comboxSearchOperation').combobox('getValue');
				if(operation !== ''){
					//alert("getText:"+fieldName);
						param.operation = operation;
				}
				
				var changeFromKettle = $('#comboxSearchSourceChange').combobox('getValue');
				
				if(changeFromKettle != ''){
					//alert("getText:"+fieldSystemName);
						param.changeFromKettle = changeFromKettle;

				}
				
				var interfaceName = $('#txtSearchInterfaceName').val();
				if(interfaceName !=""){
					//alert(jobName);
					param.interfaceName = interfaceName;
				}
				 
				var beginOfCreateTime = $('#txtBeginTime').datetimebox('getValue');
				if(beginOfCreateTime !=""){
					param.beginOfCreateTime = beginOfCreateTime;
				}
				
				var endOfCreateTime = $('#txtEndTime').datetimebox('getValue');
				if(endOfCreateTime !=""){
					param.endOfCreateTime = endOfCreateTime;
				}
				InterfaceVersionHistoryParam = param;

			}
		});
		
		$("#datagrid").datagrid('getPager').pagination({   
		    displayMsg:'当前显示从 [{from}] 到 [{to}] 共[{total}]条记录'
		}); 

});
	//查询
	function search(){
		dataRetrieval('#txtBeginTime','#txtEndTime');
	}
	
	function　exportData(){
		dataRetrieval('#txtBeginTime','#txtEndTime');
		var param = JSON.stringify(InterfaceVersionHistoryParam);
		location.href= BASE_URL_EXPORTDATA_FILE + '/InterfaceVersionHistoryExport?param='+param;
	}